formatPercentage

fun formatPercentage(value: Double, decimalChar: Char, forceDecimal: Boolean = false): String

Formats the given double 0..1.00 as a percentage with either zero (if an even percentage) or two decimal digits showing. If forceDecimal is true, digits after the decimal point will be displayed regardless of whether it is an even percentage or not.

Return

A percentage for display to the user, which will have 2 decimal digits unless it is an even integer percent, in which case it will have no decimal digits displayed.

Parameters

value

The value as a decimal (is multiplied by 100 for display).

decimalChar

The decimal character to display.

forceDecimal

True to always display digits after the decimal point, false to only display them if it is not an even integer percentage.